import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_xyf/pages/basic_widget/index.dart';
import 'package:flutter_xyf/pages/component/index.dart';
import 'package:flutter_xyf/pages/extend/index.dart';
import 'package:flutter_xyf/pages/my/my.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  //当前选中的标识
  int _currentIndex = 0;

  PageController _pageController = new PageController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        child: PageView(
          controller: _pageController,
          //不可左右滑动
          physics: NeverScrollableScrollPhysics(),
          children: [BasicWidget(), MyComponent(), MyExtend(), MyPage()],
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(
        //当前选中的Item 默认为 0
        currentIndex: _currentIndex,
        //点击回调
        onTap: (int value) {
          setState(() {
            _currentIndex = value;
            _pageController.jumpToPage(value);
          });
        },
        //显示文字
        type: BottomNavigationBarType.fixed,
        //选中的颜色
        selectedItemColor: Colors.redAccent,
        //未选中颜色
        unselectedItemColor: Colors.blueGrey,
        items: [
          BottomNavigationBarItem(
              icon: Icon(Icons.battery_std_outlined), label: "基础组件"),
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "封装组件"),
          BottomNavigationBarItem(icon: Icon(Icons.menu), label: "扩展"),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: "我的"),
        ],
      ),
    );
  }
}
